﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FSS.Core.Controls;
using Ext.Net;
using FSS.Core.Util;
using FSS.BLL.Services;
using FSS.BLL.Entities;

namespace SalesManagement.Modules.System
{
    public partial class BackupRestore : BasePage
    {
        public BackupRestore()
            : base(SCREENS.BACKUPRESTORE)
        {

        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [DirectMethod]
        public void DocumentReady()
        {
            BindingGrid();
        }
        public void BindingGrid()
        {
            try
            {
                BackupFileService backupFileS = BackupFileService.GetInstance();
                List<BackupFileEntity> lstBackupFile = backupFileS.GetAllBackupFiles();
                if (lstBackupFile == null) return;
                storeMain.DataSource = lstBackupFile;
                storeMain.DataBind();
            }
            catch (Exception ex)
            { Notification(ex.Message);
                
            }
        }
        public void btnBackup_Click(object sender, DirectEventArgs e)
        {
            BackupFileService backupFileS = BackupFileService.GetInstance();
            backupFileS.Backup();
            BindingGrid();
        }
        public void grdMain_OnCommand(object sender, DirectEventArgs e)
        {
            string fileName = e.ExtraParams["FullFileName"];
            string command = e.ExtraParams["command"];
            if (IsDelete && Constants.Edit.Equals(command))
            {
                BackupFileService backupFileS = BackupFileService.GetInstance();
                backupFileS.RestoreBackup(fileName);
                //BindingGrid();
            }
            else if (IsDelete && Constants.Delete.Equals(command))
            {
                BackupFileService backupFileS = BackupFileService.GetInstance();
                backupFileS.DeleteBackup(fileName);
                BindingGrid();
            }
        }
    }
}
